var isReply = false
var comment = function(click_target) {

        if($("#SingleComment-Template").attr('comment-rcid') === 'xxx')
        {
	        var SingleComment_new = $('#SingleDirectComment-Template').clone();
	        SingleComment_new.removeAttr('id')
	        SingleComment_new.css('display','block')
        	//direct comment 直接评论
	        var target = $("#commentArea-Output") //主评论人
	        var content_new = SingleComment_new.find('.media-body').find('div')[0].innerText= $("#InputComments").val() // val？innerText 普通DOM元素&jq对象？
	        var from_new = SingleComment_new.find('.media-heading')[0].innerHTML = SingleComment_new.attr('comment-fid')

	        //.css('background',"url('http://www.jb51.net/images/logo.gif')")

	        console.log(target.parent().find('.media-body'))
	        target.append(SingleComment_new[0])   
	            $(".SingleComment .headpic-click").click(function(){
	              do_clickHeadpic(this)
	           })             
	         console.log('reply success!')  
        }else{
	        var SingleComment_new = $('#SingleComment-Template').clone();
	        SingleComment_new.removeAttr('id')
	        SingleComment_new.css('display','block')
        	//reply comment回复评论
	        var target = $(".SingleComment").filter("[comment-cid='"+$("#SingleComment-Template").attr('comment-cid')+"']") //主评论人
	        var content_new = SingleComment_new.find('.media-body').find('div')[0].innerText= $("#InputComments").val() // val？innerText 普通DOM元素&jq对象？
	        var from_new = SingleComment_new.find('.media-heading')[0].innerHTML = SingleComment_new.attr('comment-fid')+' <strong>回复</strong> '+SingleComment_new.attr('comment-tid')+ ':'

	        //.css('background',"url('http://www.jb51.net/images/logo.gif')")

	        console.log(target.parent().find('.media-body'))
	        target.find('.media-body')[0].append(SingleComment_new[0])   
	            $(".SingleComment .headpic-click").click(function(){
	              do_clickHeadpic(this)
	           })             
	         console.log('reply success!')           
        }

  }

   var do_directComment=function(that){
      var target = $(that)
      console.log('+++++++++')
      console.log(target.parent())
      var FromWho =target.parent().attr('comment-fid') || ['Ligu','Michael','Allen','Adam','Ashely','Jiang','Bruce','Mian','Jack','Eatle'][parseInt(Math.random()*10)]
      var FromComment = target.parent().attr('comment-cid') || parseInt(Math.random()*300)
      $('#SingleDirectComment-Template').attr('comment-tid',FromWho+'')
      $('#SingleDirectComment-Template').attr('comment-fid',['Ligu','Michael','Allen','Adam','Ashely','Jiang','Bruce','Mian','Jack','Eatle'][parseInt(Math.random()*10)] + '')
      $('#SingleDirectComment-Template').attr('comment-rcid',parseInt(Math.random()*10000)+'') //which reply
      $('#SingleDirectComment-Template').attr('comment-cid',FromComment+'') //which comment
        var Random_HeadPic = ['/img/yj.jpg','/img/ligu.jpg','/img/mian.jpg','/img/eatle.jpg','/img/konan.png'][parseInt(Math.random()*4)]
        var headpic_new = $('#SingleDirectComment-Template').find('.media-object').attr('src',Random_HeadPic)      
   }
   var do_clickHeadpic=function(that){
      var target = $(that)
      console.log('+++++++++')
      console.log(target.parent())
      var FromWho =target.parent().attr('comment-fid')
      var FromComment = target.parent().attr('comment-cid')
      $('#SingleComment-Template').attr('comment-tid',FromWho+'')
      $('#SingleComment-Template').attr('comment-fid',['Ligu','Michael','Allen','Adam','Ashely','Jiang','Bruce','Mian','Jack','Eatle'][parseInt(Math.random()*10)] + '')
      $('#SingleComment-Template').attr('comment-rcid',parseInt(Math.random()*10000)+'') //which reply
      $('#SingleComment-Template').attr('comment-cid',FromComment+'') //which comment
        var Random_HeadPic = ['/img/yj.jpg','/img/ligu.jpg','/img/mian.jpg','/img/eatle.jpg','/img/konan.png'][parseInt(Math.random()*4)]
        var headpic_new = $('#SingleComment-Template').find('.media-object').attr('src',Random_HeadPic)      
   }
  $(function(){

   $(".SingleComment .headpic-click").click(function(){
   		isReply = true
      do_clickHeadpic(this)
   })
    
   $('#doComment').click(function(e){
   	if(isReply){
    	comment(this);
   	}else{
   		do_directComment(this)
   		comment(this);
   	}
   })

  })